<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>关键字搜索</title>
    <style>
        li {
            list-style: none;
            font-size: 14px;
        }

        #d {
            border: 1px solid #3344bb;
            border-top: 0px;
            width: 300px;
            padding: 2px 5px;
            max-height: 130px;
            overflow: auto;
            display: none;
        }
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("#spell").keyup(function () {
                let spell = $("#spell").val();
                if (spell == "") {
                    $("#d").hide();
                    return;
                }
                $("#d").empty();
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/query",
                    data: {"spell": spell},
                    dataType: "json",
                    success: function (datas) {
                        if (datas.length == 0) {
                            $("#d").hide();
                            return;
                        }
                        $("#d").show();
                        $(datas).each(function () {
                            $("#d").append("<li>" + this.message + "</li>")
                        })
                    }
                })

            });
        })
    </script>
</head>
<body>
<input type="text" style="width: 312px;" id="spell">
<div id="d">
</div>
</body>
</html>